﻿var defaultDate = Date.parse('1900/01/01');
function LoadFeedBack(EbayUserId, OrderId) {
    $("#tpjia").datagrid({
        border: true,
        height: 120,
        title: '评价列表...',
        remoteSort: false,
        nowrap: true,
        striped: false,
        border: false,
        rownumbers: true,
        url: "../../TableHanders.aspx?act=q&tid=1003&type=0",
        loadMsg: "正在加载,请稍后...",
        columns: [[
            { title: 'ItemTitle', field: 'ItemTitle', width: 300 },
            { title: 'User', field: 'CommentingUser', width: 130 },
            { title: 'UserScore', field: 'CommentingUserScore', width: 75 },
            { title: 'CommentText', field: 'CommentText', width: 200 },
            { title: 'CommentTime', field: 'CommentTime', width: 120 },
            { title: 'CommentType', field: 'CommentType', width: 120 },
            { title: 'Role', field: 'Role', width: 90 }
        ]],
        queryParams: {
            "EbayUserId": EbayUserId,
            "OrderId": OrderId
        }
    });
    $("#ttsu").datagrid({
        border: true,
        height: 120,
        title: '投诉列表...',
        remoteSort: false,
        nowrap: true,
        border: false,
        striped: false,
        rownumbers: true,
        singleSelect: true,
        url: "../../TableHanders.aspx?act=q&tid=1004&type=0",
        loadMsg: "正在加载,请稍后...",
        columns: [[
            { title: 'MessageSource', field: 'MessageSource', width: 80 },
            { title: 'MessageText', field: 'MessageText', width: 400 },
            { title: 'RecordType', field: 'DisputeRecordType', width: 90 },
            { title: 'State', field: 'DisputeState', width: 80 },
            { title: 'Status', field: 'DisputeStatus', width: 80 },
            { title: 'OtherPartyRole', field: 'OtherPartyRole', width: 100 },
            { title: 'OtherPartyName', field: 'OtherPartyName', width: 100 },
            { title: 'UserRole', field: 'UserRole', width: 90 },
            { title: 'DisputeReason', field: 'DisputeReason', width: 200 },
            { title: 'DisputeExplanation', field: 'DisputeExplanation', width: 150 },
            { title: 'CreditEligibility', field: 'DisputeCreditEligibility', width: 100 },
            { title: 'CreatedTime', field: 'DisputeCreatedTime', width: 120 },
            { title: 'ModifiedTime', field: 'DisputeModifiedTime', width: 120 }
        ]],
        queryParams: {
            "EbayUserId": EbayUserId,
            "OrderId": OrderId
        }
    });
}

function LoadProductReplace(EbayUserId, OrderId) {
    $("#tthlog").datagrid({
        border: true,
        noheader: true,
        height: 165,
        remoteSort: false,
        nowrap: true,
        striped: false,
        border: false,
        rownumbers: true,
        url: "../../TableHanders.aspx?act=q&tid=1008&type=0",
        loadMsg: "正在加载,请稍后...",
        columns: [[
            { title: '被替换产品Id', field: 'ProductOldId', width: 90 },
            { title: '替换产品Id', field: 'ProductNewId', width: 90 },
            { title: '被替换数量', field: 'QuantityOld', width: 80, align: 'right' },
            { title: '替换后数量', field: 'QuantityNew', width: 80, align: 'right' },
            { title: '替换日期', field: 'RepDate', width: 130 },
            { title: '操作人', field: 'RepUser', width: 60 }
        ]],
        queryParams: {
            "EbayUserId": EbayUserId,
            "OrderId": OrderId
        }
    });
}

function LoadParcelOrder(EbayUserId, OrderId) {
    $("#tfhxxi").datagrid({
        border: true,
        noheader: true,
        height: 165,
        remoteSort: false,
        nowrap: true,
        striped: false,
        border: false,
        rownumbers: true,
        url: "../../TableHanders.aspx?act=q&tid=1021&type=0",
        loadMsg: "正在加载,请稍后...",
        columns: [[
            //                    { title: '发货单号', field: 'ParcelId', width: 120 },
            //                    { title: '订单号', field: 'OrderId', width: 180 },
            //                    { title: 'Ebay帐号', field: 'EbayUserId', width: 85 },
            //                    { title: '发货日期', field: 'CreateDate', width: 130 },
            //                    { title: '操作人', field: 'Muser', width: 80 }
            { title: '发货单号', field: 'parcel_id', width: 80 },
            { title: 'SRN订单', field: 'OrderSalesRecordNumber', width: 100 },
            { title: 'RoyalMail订单号', field: 'TrackingNumber', width: 180 },
            { title: 'OrderID', field: 'orderid', width: 180 },
            { title: 'Ebay帐号', field: 'EbayUserId', width: 85 },
            { title: '实际发货方式', field: 'my_PostageService', width: 185 },
            { title: 'Memo', field: 'memo', width: 60 },
            { title: '产品代码', field: 'usercode', width: 140 },
            { title: '数量', field: 'quantity', width: 30 },
            { title: '生成日期', field: 'createDate', width: 130 },
            { title: '打印日期', field: 'printDate', width: 130 },
            { title: '扫描日期', field: 'dispatchDate', width: 130 }
        ]],
        queryParams: {
            "EbayUserId": EbayUserId,
            "OrderId": OrderId,
            "oType": 0
        }
    });
}
function LoadReParcelOrder(EbayUserId, OrderId) {
    $("#trefhxxi").datagrid({
        border: true,
        noheader: true,
        height: 165,
        remoteSort: false,
        nowrap: true,
        striped: false,
        border: false,
        rownumbers: true,
        url: "../../TableHanders.aspx?act=q&tid=1012&type=0",
        loadMsg: "正在加载,请稍后...",
        columns: [[
            { title: '新单号', field: 'OrderId', width: 160 },
            { title: '原单号', field: 'NewOrderId', width: 160 },
            { title: 'Ebay帐号', field: 'EbayUserId', width: 85 },
            { title: '重发日期', field: 'Mtime', width: 130 },
            { title: '操作人', field: 'Muser', width: 80 }
        ]],
        queryParams: {
            "EbayUserId": EbayUserId,
            "OrderId": OrderId,
            "oType": 1
        }
    });
}
function LoadTHOrder(EbayUserId, OrderId) {
    $("#tthxxi").datagrid({
        border: true,
        noheader: true,
        height: 165,
        remoteSort: false,
        nowrap: true,
        striped: false,
        border: false,
        rownumbers: true,
        url: "../../TableHanders.aspx?act=q&tid=1013&type=0",
        loadMsg: "正在加载,请稍后...",
        columns: [[
	        { title: '退货单号', field: 'ReturnsOrderId', width: 120, sortable: true },
	        { title: 'Ebay帐号', field: 'EbayUserId', width: 85, sortable: true },
	        { title: '订单号', field: 'OrderId', width: 150, align: 'center', sortable: true },
            { title: '处理情况', field: 'ProcessingStatus', width: 90, sortable: true, formatter: function (val) {
                if (val == 0) {
                    return '未处理';
                }
                else if (val == 1) {
                    return '重发';
                }
                else if (val == 2) {
                    return '退款';
                }
                else {
                    return val;
                }
            }
            },
            { title: '是否匹配', field: 'IsMatch', width: 80, sortable: true, formatter: function (val) {
                if (val == 0) {
                    return '未匹配';
                }
                else if (val == 1) {
                    return '已匹配';
                }
                else {
                    return val;
                }
            }
            },
	        { title: '同步日期', field: 'SynchronousDate', width: 120, sortable: true, formatter: function (val) {
	            var d = Date.parse(val.replace("-", "/"));
	            if (d == defaultDate) {
	                return "";
	            }
	            else {
	                return val;
	            }
	        }
	        }
        ]],
        queryParams: {
            "EbayUserId": EbayUserId,
            "OrderId": OrderId,
            "Type": 0
        }
    });
}
function LoadRefundOrder(EbayUserId, OrderId) {
    $("#tkhtkuan").datagrid({
        border: true,
        noheader: true,
        height: 165,
        remoteSort: false,
        nowrap: true,
        striped: false,
        border: false,
        rownumbers: true,
        url: "../../TableHanders.aspx?act=q&tid=1011&type=0",
        loadMsg: "正在加载,请稍后...",
        columns: [[
            { title: 'Ebay帐号', field: 'EbayUserId', width: 90 },
            { title: '订单号', field: 'OrderId', width: 160 },
            { title: '退款金额', field: 'RefundAmount', width: 80, align: 'right' },
            { title: '退款日期', field: 'RefundDate', width: 130 },
            { title: '退款状态', field: 'StatusId', width: 80, formatter: function (val, rec) {
                if (val == 0) {
                    return '未审核';
                }
                else if (val == 1) {
                    return '已审核';
                }
                else if (val == 2) {
                    return '作废';
                }
                else if (val == 3) {
                    return '已付款';
                }
                else {
                    return val;
                }
            }
            },
            { title: '退款类别', field: 'AuditFlag', width: 80, formatter: function (val, rec) {
                if (val == 1) {
                    return '审核前退款';
                }
                else if (val == 2) {
                    return '审核后退款';
                }
                else {
                    return val;
                }
            }
            },
            { title: '退款类型', field: 'RefundType', width: 200 },
            { title: '责任部门', field: 'FName', width: 80 },
            { title: '投诉状态', field: 'disputetype', width: 80, formatter: function (val, rec) {
                if (val == 0) {
                    return '未投诉';
                }
                else {
                    return '已投诉';
                }
            }
            }
        ]],
        queryParams: {
            "EbayUserId": EbayUserId,
            "OrderId": OrderId
        }
    });
}
function LoadGlProduct(EbayUserId, timeFrom, timeTo, buyerId, buyerName) {
    $("#tddglian").datagrid({
        border: true,
        noheader: true,
        height: 165,
        remoteSort: false,
        nowrap: true,
        striped: false,
        border: false,
        rownumbers: true,
        url: "../../TableHanders.aspx?act=q&tid=1009&type=0",
        loadMsg: "正在加载,请稍后...",
        columns: [[
            { title: 'OrderLineItemId', field: 'OrderLineItemId', width: 190 },
            { title: 'BuyerId', field: 'UserId', width: 90 },
            { title: 'BuyerFullName', field: 'BuyerFullName', width: 130 },
            { title: 'BuyerEmail', field: 'BuyerEmail', width: 200 },
            { title: 'Quantity', field: 'Quantity', width: 60, align: 'right' },
            { title: 'TotalPrice', field: 'TotalPrice', width: 60, align: 'right' }
        ]],
        queryParams: {
            "ebayUserId": EbayUserId,
            "timeFrom": timeFrom,
            "timeTo": timeTo,
            "buyerId": buyerId,
            "BuyerFullName": buyerName
        }
    });
}

function GetOrderStatus(val) {
    switch (val) {
    case '1':
        return "未审核";
    case '2':
        return "已审核";
    case '3':
        return "保留";
    case '4':
        return "作废";
    case '5':
        return "已退款";
    case '6':
        return "已退货";
    case '8':
        return '已合并';
    case '9':
        return '已拆分';
    case '10':
        return '发货取消';
    case '11':
        return '缺货';
    case '12':
        return '待审核'
    default:
        return val;
    }
}

//    if (val == 1) {
//        return "未审核";
//    }
//    else if (val == 2) {
//        return "已审核";
//    }
//    else if (val == 3) {
//        return "保留";
//    }
//    else if (val == 4) {
//        return "作废";
//    }
//    else if (val == 5) {
//        return "已退款";
//    }
//    else if (val == 6) {
//        return "已退货";
//    }
//    else if (val == 8) {
//        return '已合并';
//    }
//    else if (val == 9) {
//        return '已拆分';
//    }
//    else if (val == 10) {
//        return '发货取消';
//    }
//    else if (val == 11) {
//        return '缺货';
//    }
//    else if (val == 12) {
//        return '待审核'
//    }
//    else {
//        return val;
//    }
//}
function LoadOrderDetail(EbayUserId, OrderId) {
    $("#torderdetail").datagrid({
        border: true,
        height: 165,
        title: '订单明细...',
        remoteSort: false,
        nowrap: true,
        striped: false,
        border: false,
        rownumbers: true,
        singleSelect: true,
        url: "../../TableHanders.aspx?act=q&tid=1005&type=0",
        loadMsg: "正在加载,请稍后...",
        toolbar: [{
            text: '清除标准化标记',
            iconCls: 'icon-remove',
            handler: function () {
                var rows = $("#torderdetail").datagrid('getRows');
                if (rows.length == 0) {
                    alert('没有订单');
                    return;
                }
                var ebayUserId = rows[0].EbayUserId;
                var orderId = rows[0].OrderId;
                var orderstatusid = rows[0].OrderStatusId;
                if (orderstatusid == 2) {
                    alert(" 此订单已审核不可以清除标准化");
                    return;
                }
                if (!confirm('确认要清楚标准化吗?'))
                    return;
                WaitBox.Show();
                var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=updatastandard&type=1&ebId=" + EbayUserId + "&oid=" + OrderId + "&ts=" + new Date().getTime();
                $.getJSON(url, function (data) {
                    WaitBox.Close();
                    var retData = EvalData(data);
                    var code = retData.retCode;
                    if (code == 0) {
                        alert("操作完成");
                        $("#torderdetail").datagrid('reload');
                    }
                    else {
                        alert(retData.retMsg);
                    }
                });
            }
        }],
        frozenColumns: [[
            { title: '标准化操作', field: 'optDelete', width: 80, align: 'center',
              formatter: function (val, row, index) {
                  var Standard = row.Standard;
                  if (Standard == "") {
                      return "标准化标记正常";
                  }
                  var oId = row.OrderId;
                  var ebId = row.EbayUserId;
                  var olId = row.OrderLineItemId;
                  var orderstatusid = row.OrderStatusId;
                  return "<a href=\"javascript:void(0);\" onclick = \"UpdataStandard('" + oId + "','" + ebId + "','" + olId +  "','" + orderstatusid + "');\">清除</a>";
              }
            },
	        { title: 'EbayUserId', field: 'EbayUserId', width: 85, formatter: function (val, rec) {
	            if (rec.MatchStatusId == 2) {
	                return '<span style="color:red;">' + val + '</span>';
	            }
	            else {
	                return val;
	            }
	        }
	        },
	        { title: 'OrderId', field: 'OrderId', width: 180, formatter: function (val, rec) {
	            if (rec.MatchStatusId == 2) {
	                return '<span style="color:red;">' + val + '</span>';
	            }
	            else {
	                return val;
	            }
	        }
	        }
		]],
        columns: [[
	        { title: 'Rec_Number', field: 'SalesRecordNumber', width: 140, sortable: true },
            { title: 'Memo', field: 'Memo', width: 250 },
            { title: '客服备注', field: 'BeiZhu', width: 120 },
	        { title: 'CustomLable', field: 'CustomLable', width: 300, sortable: true },
	        { title: 'Listing', field: 'Listing', width: 300, sortable: true },
	        { title: 'OrderLineItemId', field: 'OrderLineItemId', width: 180 },
	        { title: 'ItemId', field: 'ItemId', width: 120 },
	        { title: 'ItemTitle', field: 'ItemTitle', width: 300 },
	        { title: '数量', field: 'Quantity', width: 70, align: 'right' },
	        { title: '赠送数量', field: 'SendQuantity', width: 70, align: 'right' },
	        { title: '下单日期', field: 'SaleDate', width: 130 },
	        { title: '销售总额', field: 'TotalPrice', width: 80, align: 'right' },
	        { title: '运费', field: 'yf', width: 80, align: 'right' },
	        { title: '总金额', field: 'tp', width: 80, align: 'right' },
	        { title: 'ebay发货方式', field: 'PostageService', width: 200 },
	        { title: '标准化', field: 'Standard', width: 300, formatter: function (val, rec) {
	            if (val == "") {
	                return val;
	            }
	            else {
	                return '<span style="color:Green;font-weight:bold;">' + val + '</span>';
	            }
	        }
	        },
	        { title: '订单状态', field: 'OrderStatusId', width: 60, sortable: true, formatter: function (val, rec) {
	            return GetOrderStatus(val);
	        }
	        },
	        { title: '订单保留原因', field: 'OrderRetentionReson', width: 80 },
	        { title: '不完全代码处理', field: 'IsOutStock', width: 80, formatter: function (val, rec) {
	            if (val == 'Y') {
	                return "已处理";
	            }
	            else {
	                return "";
	            }
	        }
	        },
	        { title: '付款情况', field: 'IsPay', width: 80, sortable: true, formatter: function (val, rec) {
	            if (val == 'Y') {
	                return "已付款";
	            }
	            else {
	                return "未付款";
	            }
	        }
	        },
	        { title: '发货情况', field: 'DeliveryStatus', width: 80 },
	        { title: '评价状态', field: 'FeedBackStatus', width: 80 },
	        { title: '退款情况', field: 'RefundStatus', width: 80 },
	        { title: '退货情况', field: 'ReturnsStatus', width: 80 },
	        { title: '是否重新发货', field: 'IsReBuilderOrder', width: 80, formatter: function (val, rec) {
	            if (val == 'Y') {
	                return "是";
	            }
	            else {
	                return "否";
	            }
	        }
	        },
	        { title: '重发原因', field: 'ReBuilderReson', width: 300 },
			{ title: 'PDate', field: 'PDate', width: 130, formatter: function (val) {
				var d = Date.parse(val.replace("-", "/"));
				if (d == defaultDate) {
					return "";
				}
				else {
					return val;
				}
			}
			},
			{ title: '匹配时间', field: 'MatchDate', width: 130, formatter: function (val) {
				var d = Date.parse(val.replace("-", "/"));
				if (d == defaultDate) {
					return "";
				}
				else {
					return val;
				}
			}
			},
			{ title: '打印时间', field: 'PrintDate', width: 130, formatter: function (val) {
				var d = Date.parse(val.replace("-", "/"));
				if (d == defaultDate) {
					return "";
				}
				else {
					return val;
				}
			}
			},
	        { title: '打印人', field: 'PrintUserId', width: 120 },
	        { title: '发货时间', field: 'DeliveryDate', width: 130, formatter: function (val) {
	            var d = Date.parse(val.replace("-", "/"));
	            if (d == defaultDate) {
	                return "";
	            }
	            else {
	                return val;
	            }
	        }
	        },
	        { title: '发货人', field: 'DeliveryUser', width: 120 },

	        { title: '作废时间', field: 'CancelDate', width: 130, formatter: function (val) {
	            var d = Date.parse(val.replace("-", "/"));
	            if (d == defaultDate) {
	                return "";
	            }
	            else {
	                return val;
	            }
	        }
	        },
	        { title: '作废人', field: 'CancelUser', width: 120 },
	        { title: '订单备注', field: 'Mnote', width: 120 },
	        { title: 'UserId', field: 'UserId', width: 120 },
	        { title: 'BuyerFullName', field: 'BuyerFullName', width: 200 },
	        { title: 'BuyerEmail', field: 'BuyerEmail', width: 200 },
	        { title: 'BuyerAddress1', field: 'BuyerAddress1', width: 200 },
	        { title: 'BuyerAddress2', field: 'BuyerAddress2', width: 200 },
	        { title: 'BuyerCity', field: 'BuyerCity', width: 120 },
	        { title: 'BuyerCounty', field: 'BuyerCounty', width: 120 },
	        { title: 'BuyerPostcode', field: 'BuyerPostcode', width: 80 },
	        { title: 'BuyerCountry', field: 'BuyerCountry', width: 80 },
	        { title: 'BuyerPhoneNumber', field: 'BuyerPhoneNumber', width: 80 },
            { title: '实际发货方式', field: 'Delivery', width: 180 }, 	                
	        { title: 'PPBuyerId', field: 'BuyerId', width: 120 },
	        { title: 'PPBuyerName', field: 'BuyerName', width: 120 },
	        { title: 'AddressLine1', field: 'AddressLine1', width: 120 },
	        { title: 'AddressLine2', field: 'AddressLine2', width: 120 },
	        { title: 'TownCity', field: 'City', width: 120 },
	        { title: 'StateProvince', field: 'County', width: 120 },
	        { title: 'PostalCode', field: 'PostalCode', width: 120 },
	        { title: 'Country', field: 'Country', width: 120 },
	        { title: 'ContactPhoneNumber', field: 'ContactPhoneNumber', width: 120 }
		]],
        onDblClickRow: function (rowIndex, rowData) {
            var mid = rowData.MatchStatusId;
            var orderstutsid = rowData.OrderStatusId;
            if (orderstutsid == 2) {
                alert('此订单已审核');
                return;
            }
            var isp = rowData.IsPay;
            if (mid == 2 && isp == "Y") {
                var id = rowData.EbayUserId;
                var id2 = rowData.OrderLineItemId;
                var id3 = rowData.OrderId;
                var ret = window.showModalDialog("UpdateOrder.aspx?id=" + id + "&id2=" + id2 + "&id3=" + id3 + "&ts=" + new Date().getTime(), "", "dialogHeight:500px;dialogWidth:630px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;");
                if (ret) {
                    $("#torderdetail").datagrid('reload');
                }
            }
            else {
                alert('只有已匹配并且已付款的单据才可以修改');
                return;
            }
        },
        queryParams: {
            "EbayUserId": EbayUserId,
            "OrderId": OrderId
        }
    });
}
function UpdataStandard(oId, ebId, olId, orderstatusid) {
    if (orderstatusid == 2) {
        alert("此订单已审核不可以清除标准化");
        return;
    }

    if (!confirm('确认要清楚标准化吗?'))
        return;
    WaitBox.Show();
    var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=updatastandard&type=0&oId=" + oId + "&ebId=" + ebId + "&olId=" + olId + "&ts=" + new Date().getTime();
    $.getJSON(url, function (data) {
        WaitBox.Close();
        var retData = EvalData(data);
        var code = retData.retCode;
        if (code == 0) {
            alert("操作完成");
            $("#torderdetail").datagrid('reload');
        }
        else {
            alert(retData.retMsg);
        }
    });
}
function LoadPPDetail(EbayUserId, OrderId) {
    $("#tppdetail").datagrid({
        border: true,
        height: 165,
        title: 'PayPal明细...',
        remoteSort: false,
        nowrap: true,
        striped: false,
        border: false,
        rownumbers: true,
        singleSelect: true,
        url: "../../TableHanders.aspx?act=q&tid=1006&type=0",
        loadMsg: "正在加载,请稍后...",
        frozenColumns: [[
	        { title: 'EbayUserId', field: 'EbayUserId', width: 120 },
	        { title: 'TransactionId', field: 'TransactionId', width: 130, formatter: function (val, rec) {
	            if (rec.StatusId == '2') {
	                return '<span style="color:red;">' + val + '</span>';
	            }
	            else {
	                return val;
	            }
	        }
	        }
		]],
        columns: [[
	        { title: 'Date', field: 'CreateDateTime', width: 130 },
			{ field: 'BuyerID', title: 'BuyerID', width: 130 },
	        { title: 'Name', field: 'Name', width: 150 },
	        { title: 'FromEmailAddress', field: 'FromEmailAddress', width: 200 },
	        { title: 'ToEmailAddress', field: 'ToEmailAddress', width: 200 },
	        { title: 'ItemId', field: 'ItemID', width: 120 },
	        { title: 'ItemTitle', field: 'ItemTitle', width: 300 },
			{ field: 'ReferenceTxnID', title: 'ReferenceTxnID', width: 85 },
	        { title: 'Currency', field: 'Currency', width: 80 },
	        { title: 'Gross', field: 'Gross', width: 80, align: 'right' },
	        { title: 'Fee', field: 'Fee', width: 80, align: 'right' },
	        { title: 'Net', field: 'Net', width: 80, align: 'right' },
			{ field: 'PostageandPackingAmount', title: 'PostageandPackingAmount', width: 150, align: 'right' },
	        { title: 'Type', field: 'Type', width: 200 },
	        { title: 'Status', field: 'Status', width: 120 },
			{ field: 'AddressLine1', title: 'AddressLine1', width: 200 },
			{ field: 'AddressLine2', title: 'AddressLine2', width: 200 },
			{ field: 'City', title: 'Town/City', width: 85 },
			{ field: 'County', title: 'County', width: 85 },
			{ field: 'PostalCode', title: 'PostalCode', width: 85 },
			{ field: 'Country', title: 'Country', width: 85 },
			{ field: 'ContactPhoneNumber', title: 'ContactPhoneNumber', width: 130 },
			{ field: 'ImportDate', title: '导入时间', width: 130, formatter: function (val) {
				var d = Date.parse(val.replace("-", "/"));
				if (d == defaultDate) {
					return "";
				}
				else {
					return val;
				}
			}
			},
			{ field: 'ToInvoice', title: '已发货', width: 80, sortable: true, formatter: function (val, rec) {
				if (val == 'Y') {
					return '是';
				}
				else {
					return '否';
				}
			}
			},
			{ field: 'ToPz', title: '写入凭证', width: 80, sortable: true, formatter: function (val, rec) {
				if (val == 'Y') {
					return '是';
				}
				else {
					return '否';
				}
			}
			},
			{ field: 'StatusId', title: '状态', width: 50, formatter: function (val, rec) {
				if (val == '2') {
					return '<span style="color:red;">已匹配</span>';
				}
				else {
					return '未匹配';
				}
			}
	        },
            { title: 'OrderID', field: 'OrderId', width: 120 }
		]],
        queryParams: {
            "EbayUserId": EbayUserId,
            "OrderId": OrderId
        }
    });
}

function TabsClear() {
    var divDD = $('#divddmxi').children()[0].tagName;
    var divSP = $('#divspmxi').children()[0].tagName;
    var divPP = $('#divppmxi').children()[0].tagName;
    var divFH = $('#divfhxxi').children()[0].tagName;
    var divPJ = $('#divpjtsu-c-pjia').children()[0].tagName;
    var divTS = $('#divpjtsu-c-tsu').children()[0].tagName;
    var divTH = $('#divthuo').children()[0].tagName;
    var divTK = $('#divtkuan').children()[0].tagName;
    var divCF = $('#divcfa').children()[0].tagName;
    if (divDD=="DIV") {
        $('#torderdetail').datagrid('loadData', { total: 0, rows: [] });
    }
    if (divSP == "DIV") {
        $('#tproduct').datagrid('loadData', { total: 0, rows: [] });
    }
    if (divPP == "DIV") {
        $('#tppdetail').datagrid('loadData', { total: 0, rows: [] });
    }
    if (divFH == "DIV") {
        $('#tfhxxi').datagrid('loadData', { total: 0, rows: [] });
    }
    if (divPJ == "DIV") {
        $('#tpjia').datagrid('loadData', { total: 0, rows: [] });       
    }
    if (divTS == "DIV") {        
        $('#ttsu').datagrid('loadData', { total: 0, rows: [] });
    }
    if (divTH == "DIV") {
        $('#tthxxi').datagrid('loadData', { total: 0, rows: [] });
    }
    if (divTK == "DIV") {
        $('#tkhtkuan').datagrid('loadData', { total: 0, rows: [] });
    }
    if (divCF == "DIV") {
        $('#trefhxxi').datagrid('loadData', { total: 0, rows: [] });
    }
    //    var divDD = document.getElementById('divddmxi').innerHTML;
    //    var divSP = document.getElementById('divspmxi').innerHTML;
    //    var divPP = document.getElementById('divppmxi').innerHTML;
    //    var divFH = document.getElementById('divfhxxi').innerHTML;
    //    var divPJ = document.getElementById('divpjtsu').innerHTML;
    //    var divTH = document.getElementById('divthuo').innerHTML;
    //    var divTK = document.getElementById('divtkuan').innerHTML;
    //    var divCF = document.getElementById('divcfa').innerHTML;
    //    var divDDCount = divDD.length;
    //    var divSPCount = divSP.length;
    //    var divPPCount = divPP.length;
    //    var divFHCount = divFH.length;
    //    var divPJCount = divPJ.length;
    //    var divTHCount = divTH.length;
    //    var divTKCount = divTK.length;
    //    var divCFCount = divCF.length;    
    //    if (divDDCount > 50) {
    //        $('#torderdetail').datagrid('loadData', { total: 0, rows: [] });
    //    }
    //    if (divSPCount > 50) {
    //        $('#tproduct').datagrid('loadData', { total: 0, rows: [] });
    //    }
    //    if (divPPCount > 50) {
    //        $('#tppdetail').datagrid('loadData', { total: 0, rows: [] });
    //    }
    //    if (divFHCount > 50) {
    //        $('#tfhxxi').datagrid('loadData', { total: 0, rows: [] });
    //    }
    //    if (divPJCount > 1500) {
    //        $('#tpjia').datagrid('loadData', { total: 0, rows: [] });
    //        $('#ttsu').datagrid('loadData', { total: 0, rows: [] });
    //    }
    //    if (divTHCount > 50) {
    //        $('#tthxxi').datagrid('loadData', { total: 0, rows: [] });
    //    }
    //    if (divTKCount > 50) {
    //        $('#tkhtkuan').datagrid('loadData', { total: 0, rows: [] });
    //    }
    //    if (divCFCount > 50) {
    //        $('#trefhxxi').datagrid('loadData', { total: 0, rows: [] });
    //    }
}

function LoadProductDetail(EbayUserId, OrderId) {
    $("#tproduct").datagrid({
        border: true,
        height: 165,
        title: '商品明细...',
        remoteSort: false,
        nowrap: true,
        striped: false,
        border: false,
        rownumbers: true,
        singleSelect: true,
        url: "../../TableHanders.aspx?act=q&tid=1007&type=0",
        loadMsg: "正在加载,请稍后...",
        toolbar: [{
            text: '添加商品',
            iconCls: 'icon-remove',
            handler: function () {
                var rows = $("#torderdetail").datagrid('getRows');
                if (rows.length == 0) {
                    alert('没有订单或请先查看订单明细');
                    return;
                }
                var oids = rows[0].OrderId;
                var ebayuserid = rows[0].EbayUserId;
                var orderstatusid = rows[0].OrderStatusId
                if (orderstatusid == 2) {
                    alert("此订单已审核不可以添加");
                    return;
                }
                $('#ddloLineitemId').combobox({
                    url: "../../TableHanders.aspx?act=q&tid=1024&type=1&ebayUserId=" + encodeURIComponent(ebayuserid) + "&OrderId=" + encodeURIComponent(oids) + "&ts=" + new Date().getTime(),
                    valueField: 'OrderLineItemId',
                    textField: 'OrderLineItemId'
                });
                $("#txtebayid").val(ebayuserid);
                $("#txtOrdersId").val(oids);
                $('#Divxzspin').window('open');
            }
        }],
        frozenColumns: [[
            { title: '删除', field: 'optDelete', width: 40, align: 'center',
              formatter: function (val, row, index) {
                  var olId = row.OrderLineItemId;
                  var ebId = row.EbayUserId;
                  var pId = row.ProductId;
                  var orderstatusid = row.OrderStatusId;

                  return "<a href=\"javascript:void(0);\" onclick = \"DeleteProduct('" + olId + "','" + ebId + "','" + pId + "','" + orderstatusid + "');\">Delete</a>";
              }
            },
            { title: '新增', field: 'optInsert', width: 30, align: 'center',
              formatter: function (val, row, index) {
                  var olId = row.OrderLineItemId;
                  var ebId = row.EbayUserId;
                  var fsId = row.WarehouseId;
                  var orderstatusid = row.OrderStatusId;

                  return "<a href=\"javascript:void(0);\" onclick = \"InsertProduct('" + olId + "','" + ebId + "','" + fsId + "','" + orderstatusid + "');\">Add</a>";
              }
            },
            { title: 'Rec_Num', field: 'SalesRecordNumber', width: 80 },
            { title: '商品代号', field: 'ProductId', width: 130 }
        ]],
        columns: [[
            { title: '规格', field: 'ProductSpecification', width: 150 },
            { title: '发货仓库', field: 'FName', width: 90, align: 'right' },
            { title: '订单数量', field: 'SingleQuantity', width: 60, align: 'right' },
            { title: '商品数量', field: 'TotalQuantity', width: 70, align: 'right' },
            { title: '锁定库存', field: 'sQty', width: 60, align: 'right' },
            { title: 'K3库存', field: 'fQty', width: 60, align: 'right' },
            { title: '商品名称', field: 'ProductName', width: 270 },
            { title: '销售组', field: 'SalesGroup', width: 80 },
            { title: '商品类别', field: 'CategoryName', width: 120 },
            { title: 'OrderId', field: 'OrderId', width: 120 },
            { title: '账户', field: 'EbayUserId', width: 80 }
        ]],
        onDblClickRow: function (rowIndex, rowData) {
            var olId = rowData.OrderLineItemId;
            var ebId = rowData.EbayUserId;
            var pid = rowData.ProductId;
            var fsId = rowData.WarehouseId;
            ShowProductDetail(olId, ebId, pid, fsId, "U");
        },
        queryParams: {
            "EbayUserId": EbayUserId,
            "OrderId": OrderId
        }
    });
}

function InsertProduct(olId, ebId, fsId, orderstatusid) {
    if (orderstatusid == 2) {
        alert(" 此订单已审核不可以新增");
        return;
    }
    var ret = window.showModalDialog("CustomerResolveBrowse.aspx?iType=I&olId=" + olId + "&ebId=" + ebId + "&fsId=" + fsId + "&ts=" + new Date().getTime(), "", "dialogHeight:300px;dialogWidth:610px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;");
    if (ret) {
        $("#tproduct").datagrid('reload');
    }
}

function DeleteProduct(olId, ebId, pId, orderstatusid) {
    if (orderstatusid == 2) {
        alert("此订单已审核不可以删除");
        return;
    }
    $.messager.confirm("请确认...", "确认删除?", function (value) {
        if (value) {
            var url = "../../TableHanders.aspx?act=d&tid=53&type=1&olId=" + olId + "&ebId=" + ebId + "&pId=" + pId + "&ts=" + new Date().getTime();
            $.getJSON(
                url,
                function (data) {
                    var sdata = data[0];
                    var code = sdata.code;
                    if (code == 0) {
                        alert('删除成功');
                        $("#tproduct").datagrid('reload');
                    }
                    else {
                        alert(sdata.msg);
                    }
                }
            );
        }
    });
}
function ShowProductDetail(olId, ebId, pid, fsId, iType) {
    var ret = window.showModalDialog("CustomerResolveBrowse.aspx?olId=" + olId + "&ebId=" + ebId + "&pid=" + pid + "&fsId=" + fsId + "&iType=" + iType + "&ts=" + new Date().getTime(), "", "dialogHeight:300px;dialogWidth:610px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;");
    if (ret) {
        alert('操作完成');
        $("#tproduct").datagrid('reload');
    }
}

function RefreshTab(ebayUserId, OrderId) {
    var pp = $('#tabs').tabs('getSelected');
    var PanleTitle = pp.panel('options').title;    
    if (PanleTitle == "商品明细") {
        LoadProductDetail(ebayUserId, OrderId);
    }
    if (PanleTitle == "订单明细") {
        LoadOrderDetail(ebayUserId, OrderId);
    }
    if (PanleTitle == "PayPal明细") {
        LoadPPDetail(ebayUserId, OrderId);
    }
    if (PanleTitle == "发货信息") {
        LoadParcelOrder(ebayUserId, OrderId);
    }
    if (PanleTitle == "评价投诉") {
        LoadFeedBack(ebayUserId, OrderId);
    }
    if (PanleTitle == "退货信息") {
        LoadTHOrder(ebayUserId, OrderId);
    }
    if (PanleTitle == "退款信息") {
        LoadRefundOrder(ebayUserId, OrderId);
    }
    if (PanleTitle == "重发信息") {
        LoadReParcelOrder(ebayUserId, OrderId);
    }
    
    //    LoadFeedBack(ebayUserId, OrderId);
    //    LoadOrderDetail(ebayUserId, OrderId);
    //    LoadPPDetail(ebayUserId, OrderId);
    //    LoadProductDetail(ebayUserId, OrderId);
    //    LoadRefundOrder(ebayUserId, OrderId);
    //    LoadTHOrder(ebayUserId, OrderId);
    //    LoadReParcelOrder(ebayUserId, OrderId);
    //    LoadParcelOrder(ebayUserId, OrderId);
}

function getdate() {
    var now = new Date()
    y = now.getFullYear()
    m = now.getMonth() + 1
    d = now.getDate()
    m = m < 10 ? "0" + m : m
    d = d < 10 ? "0" + d : d
    return y + "-" + m + "-" + d
}

function btnNewNegative() {
    var rows = $("#orders").datagrid('getSelections');
    if (rows.length != 1) {
        alert('订单负评新增只能选择一项');
        return;
    }

    $('#nEbayUserId').attr('value', rows[0].EbayUserId);
    $('#nOrderSalesRecordNumber').attr('value', rows[0].OrderSalesRecordNumber);
    $('#nCommentText').attr('value', '');
    $('#nItemID').attr('value', '');
    $('#nCommentTime').datebox('setValue', getdate()); 

    $('#mydialog').show();
    $('#mydialog').dialog({
        modal: true,
        collapsible: true,
        minimizable: true,
        maximizable: true,
        buttons: [{
            text: '提交',
            iconCls: 'icon-ok',
            handler: function () {
                Order.ResetStatus();
                Order.successMsg = '操作完成';
                Order.confirmMsg = '确认新增负评订单?';
                Order.data.cmd = 'NewNegative';
                Order.data.data = $('#nEbayUserId').val() + '※' + $('#nOrderSalesRecordNumber').val() + '※' + $('#nCommentText').val() + '※' + $('#nItemID').val() + '※' + $('#nCommentTime').datebox('getValue');
                Order.Exec();
                $('#mydialog').dialog('close');
            }
        }, {
            text: '取消',
            handler: function () {
                $('#mydialog').dialog('close');
            }
        }]
    });
}

$(function () {
    $("#ddlebayUserId").combobox({
        editable: false
    });
    $('#dlgAuditMore').dialog({
        closed: true,
        height: 160,
        width: 240,
        modal: false,
        onOpen: function () {
            $("#txtAuditCount").val("");
            $("#rdAuditCount").attr("checked", true);
        }
    });
    // Button OK in audit dialog click
    $('#btnAuditMoreOK').click(function () {
        $('#dlgAuditMore').dialog('close');
        var item = $('input:[name=AuditType]:checked').val();
        switch (item) {
        case "rdAllPreAudit":
            Order.AllPreAudit();
            break;
        case "rdPreAudit":
            Order.PreAudit();
            break;
        case "rdAudit":
            Order.Audit();
            break;
        default:
            break;
        }
        $('#dlgAuditMore').dialog('close');
    });
    //    // 全部待审
    //    $('#btnAllPreAudit').click(function () {
    //        if (!confirm('确认进行全部待审操作吗?')) {
    //            return;
    //        }
    //        $('#dlgAuditMore').dialog('close');
    //        Order.AllPreAudit();
    //    });
    //    // 选中待审
    //    $('#btnPreAudit').click(function () {
    //        if (!confirm('确认进行选中待审操作吗?')) {
    //            return;
    //        }
    //        $('#dlgAuditMore').dialog('close');
    //        Order.PreAudit();
    //    });
    //    // 选中取消待审
    //    $('#btnCancelPreAudit').click(function () {
    //        if (!confirm('确认进行取消选中待审操作吗?')) {
    //            return;
    //        }
    //        $('#dlgAuditMore').dialog('close');
    //        Order.CancelPreAudit();
    //    });
    //    // 审核
    //    $('#btnAudit').click(function () {
    //        if (!confirm('确认进行审核操作吗?')) {
    //            return;
    //        }
    //        $('#dlgAuditMore').dialog('close');
    //        Order.Audit();
    //    });
    $('#btnAuditMoreCancel').click(function () {
        $('#dlgAuditMore').dialog('close');
    });
    var _$order = $("#orders");
    Order._Order = _$order;
    _$order.datagrid({
        border: true,
        height: 325,
        width: 1100,
        title: '订单列表...',
        remoteSort: true,
        nowrap: true,
        striped: false,
        //        url: "../../TableHanders.aspx?act=q&tid=46&type=0",
        sortName: 'OrderId',
        sortOrder: 'asc',
        loadMsg: "正在加载,请稍后...",
        frozenColumns: [[
            { field: 'ck', title: '', checkbox: true },
	        { title: 'EbayAccId', field: 'EbayUserId', width: 85, sortable: true, formatter: function (val, rec) {
	            if (rec.MatchStatusId == 2 && (rec.OrderStatusId < 8 || rec.OrderStatusId == 12)) {
	                return '<span style="color:red;">' + val + '</span>';
	            }
	            else {
	                return val;
	            }
	        }
	        },
	        { title: 'OrderId', field: 'OrderId', width: 180, sortable: true, formatter: function (val, rec) {
	            if (rec.MatchStatusId == 2 && (rec.OrderStatusId < 8 || rec.OrderStatusId == 12)) {
	                return '<span style="color:red;">' + val + '</span>';
	            }
	            else {
	                return val;
	            }
	        }
	        }
		]],
        columns: [[
	        { title: 'Rec_Number', field: 'OrderSalesRecordNumber', width: 80, sortable: true },
	        { title: '原单号/新单号', field: 'NewOrderId', width: 140, sortable: true },
	        { title: 'BuyerId', field: 'UserId', width: 180, sortable: true },
	        { title: 'BuyerFullName', field: 'BuyerFullName', width: 180, sortable: true },
	        { title: 'BuyerEmail', field: 'BuyerEmail', width: 200, sortable: true },
            //	                { title: 'TotalQuantity', field: 'TotalQuantity', width: 80, sortable: true, align: 'right' },
            //	                { title: 'TotalPrice', field: 'TotalPrice', width: 80, sortable: true, align: 'right' },
	        {title: '付款情况', field: 'IsPay', width: 80, sortable: true, formatter: function (val, rec) {
	            if (val == 'Y') {
	                return "已付款";
	            }
	            else {
	                return "未付款";
	            }
	        }
	        },
            { title: '付款时间', field: 'PDate', width: 130, sortable: true, align: 'center' },
	        { title: '订单状态', field: 'OrderStatusId', width: 130, sortable: true, formatter: function (val, rec) {
	            return GetOrderStatus(val);
	        }
	        },
            { title: '审核时间', field: 'Atime', width: 130, sortable: true, align: 'center' },
			{ field: 'MatchStatusId', title: '匹配状态', width: 60, sortable: true, formatter: function (val, rec) {
				if (val == 2) {
					return '<span style="color:red;">已匹配</span>';
				}
				else if (val == 1) {
					return '新导入';
				}
				else {
					return val;
				}
			}
			},
            { title: '匹配时间', field: 'MatchDate', width: 130, sortable: true, align: 'center' }
		]],
        pagination: true,
        rownumbers: true,
        pageList: [10, 15, 20, 50, 100],
        rowStyler: function (index, row, css) {
            var oStatusId = row.OrderStatusId;
            if (oStatusId == 9 || oStatusId == 8) {
                return 'color:#C0C0C0;';
            }
        },
        onDblClickRow: function (rowIndex, rowData) {
            var OrderId = rowData.OrderId;
            var ebayUserId = rowData.EbayUserId;
            _$order.datagrid('clearSelections');
            _$order.datagrid('selectRow', rowIndex);
            RefreshTab(ebayUserId, OrderId);
        },
        onSelect: function (rowIndex, rowData) {
            var rows = _$order.datagrid('getSelections');
        },
        //        queryParams: {
        //            "timeFrom": $("#beginDate").val(),
        //            "timeTo": $("#endDate").val(),
        //            "EbayUserId": "",
        //            "OrderId": "",
        //            "BuyerId": "",
        //            "BuyerName": "",
        //            "NewOrderId": "",
        //            "OrderStatusId": "",
        //            "rtype": 1,
        //            "Standard": "Select",
        //            "ItemId": "",
        //            "userCode": "",
        //            "deliveryId2": "",
        //            "qtype": "0"
        //        },
        onBeforeLoad: function () {
            clickRowIndex = -1;
            TabsClear();
        },
        onLoadError: function () {
            alert('数据加载失败!');
        }
    });
    $('#tabs').tabs({
        height: 200,
        width: 1100,
        onSelect: function (title) {
            var rowSel = Order.GetSelectedRows();
            if (rowSel.length > 0) {
                var ebayUserId = rowSel[0].EbayUserId;
                var OrderId = rowSel[0].OrderId;
                if (rowSel.length == 1) {
                    if (title == "商品明细") {
                        var divSP = $('#divspmxi').children()[0].tagName;
                        if (divSP == "TABLE") {
                            LoadProductDetail(ebayUserId, OrderId);
                        }
                        else {
                            var DateSP = $('#tproduct').datagrid('getRows');
                            if (DateSP == 0) {
                                LoadProductDetail(ebayUserId, OrderId);
                            }
                            else {
                                var EbayUserIdSP = DateSP[0].EbayUserId;
                                var OrderIdSP = DateSP[0].OrderId;
                                if (ebayUserId != EbayUserIdSP || OrderId != OrderIdSP) {
                                    LoadProductDetail(ebayUserId, OrderId);
                                }
                            }
                        }
                    }
                    if (title == "订单明细") {
                        var divDD = $('#divddmxi').children()[0].tagName;
                        if (divDD == "TABLE") {
                            LoadOrderDetail(ebayUserId, OrderId);
                        }
                        else {
                            var DateDD = $('#torderdetail').datagrid('getRows');
                            if (DateDD == 0) {
                                LoadOrderDetail(ebayUserId, OrderId);
                            }
                            else {
                                var EbayUserIdDD = DateDD[0].EbayUserId;
                                var OrderIdDD = DateDD[0].OrderId;
                                if (ebayUserId != EbayUserIdDD || OrderId != OrderIdDD) {
                                    LoadOrderDetail(ebayUserId, OrderId);
                                }
                            }
                        }
                    }
                    if (title == "PayPal明细") {
                        var divPP = $('#divppmxi').children()[0].tagName;
                        if (divPP == "TABLE") {
                            LoadPPDetail(ebayUserId, OrderId);
                        }
                        else {
                            var DatePP = $('#tppdetail').datagrid('getRows');
                            if (DatePP == 0) {
                                LoadPPDetail(ebayUserId, OrderId);
                            }
                            else {
                                var EbayUserIdPP = DatePP[0].EbayUserId;
                                var OrderIdPP = DatePP[0].OrderId;
                                if (ebayUserId != EbayUserIdPP || OrderId != OrderIdPP) {
                                    LoadPPDetail(ebayUserId, OrderId);
                                }
                            }
                        }
                    }
                    if (title == "发货信息") {
                        var divFH = $('#divfhxxi').children()[0].tagName;
                        if (divFH == "TABLE") {
                            LoadParcelOrder(ebayUserId, OrderId);
                        }
                        else {
                            var DateFH = $('#tfhxxi').datagrid('getRows');
                            if (DateFH == 0) {
                                LoadParcelOrder(ebayUserId, OrderId);
                            }
                            else {
                                var EbayUserIdFH = DateFH[0].EbayUserId;
                                var OrderIdFH = DateFH[0].orderid;
                                if (ebayUserId != EbayUserIdFH || OrderId != OrderIdFH) {
                                    LoadParcelOrder(ebayUserId, OrderId);
                                }
                            }
                        }
                    }
                    if (title == "评价投诉") {
                        LoadFeedBack(ebayUserId, OrderId);
                    }
                    if (title == "退货信息") {
                        var divTH = $('#divthuo').children()[0].tagName;
                        if (divTH == "TABLE") {
                            LoadTHOrder(ebayUserId, OrderId);
                        }
                        else {
                            var DateTH = $('#tthxxi').datagrid('getRows');
                            if (DateTH == 0) {
                                LoadTHOrder(ebayUserId, OrderId);
                            }
                            else {
                                var EbayUserIdTH = DateTH[0].EbayUserId;
                                var OrderIdTH = DateTH[0].OrderId;
                                if (ebayUserId != EbayUserIdTH || OrderId != OrderIdTH) {
                                    LoadTHOrder(ebayUserId, OrderId);
                                }
                            }
                        }
                    }
                    if (title == "退款信息") {
                        var divTK = $('#divtkuan').children()[0].tagName;
                        if (divTK == "TABLE") {
                            LoadRefundOrder(ebayUserId, OrderId);
                        }
                        else {
                            var DateTK = $('#tkhtkuan').datagrid('getRows');
                            if (DateTK == 0) {
                                LoadRefundOrder(ebayUserId, OrderId);
                            }
                            else {
                                var EbayUserIdTK = DateTK[0].EbayUserId;
                                var OrderIdTK = DateTK[0].OrderId;
                                if (ebayUserId != EbayUserIdTK || OrderId != OrderIdTK) {
                                    LoadRefundOrder(ebayUserId, OrderId);
                                }
                            }
                        }
                    }
                    if (title == "重发信息") {
                        var divCF = $('#divcfa').children()[0].tagName;
                        if (divCF == "TABLE") {
                            LoadReParcelOrder(ebayUserId, OrderId);
                        }
                        else {
                            var DateCF = $('#trefhxxi').datagrid('getRows');
                            if (DateCF == 0) {
                                LoadReParcelOrder(ebayUserId, OrderId);
                            }
                            else {
                                var EbayUserIdCF = DateCF[0].EbayUserId;
                                var OrderIdCF = DateCF[0].NewOrderId;
                                if (ebayUserId != EbayUserIdCF || OrderId != OrderIdCF) {
                                    LoadReParcelOrder(ebayUserId, OrderId);
                                }
                            }
                        }
                    }
                }
            }
        }
    });
    $('#divpjtsu-c').tabs();
    $("#btnQuery").click(function () {
        if (!$("#p").form('validate'))
            return;
        var data = Order.getParasData();
        _$order.datagrid({
            url: "../../TableHanders.aspx?act=q&tid=46&type=0",
            queryParams: data
        });
    });
    $('#beginDate').datebox({ formatter: function (date) {
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        return y + "-" + m + "-" + d;
    }
                            });
    $('#endDate').datebox({ formatter: function (date) {
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        return y + "-" + m + "-" + d;
    }
                          });


    //*******************新增商品开始***************************

    //添加商品开始
    $('#Divxzspin').window({
        width: 600,
        height: 300,
        modal: true,
        shadow: false,
        closed: true,
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: false
    });

    $("#btnxzspClose").click(function () {
        $('#ddloLineitemId').combobox('clear');
        $("#txtebayid").val("");
        $("#txtOrdersId").val("");
        $('#Divxzspin').window('close');
    });
    //新增商品
    $("#btnxzspinOk").click(function () {
        var oid = $("#txtOrdersId").val();
        var olId = $('#ddloLineitemId').combobox('getValue');
        var ebId = $("#txtebayid").val();
        // var fsId = $('#ddlWarehouseId').combobox('getValue');
        var fsId = "";
        if (olId == "") {
            alert('子订单号不能为空');
            return;
        }
        $('#Divxzspin').window('close');
        var ret = window.showModalDialog("CustomerResolveBrowse.aspx?iType=I&olId=" + olId + "&ebId=" + ebId + "&fsId=" + fsId + "&ts=" + new Date().getTime(), "", "dialogHeight:300px;dialogWidth:610px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;");
        if (ret) {
            $("#tproduct").datagrid('reload');
            $('#ddloLineitemId').combobox('clear');
            $("#txtebayid").val("");
            $("#txtOrdersId").val("");
        }
    });
    //*******************添加商品结束***************************

    //替换开始
    $('#pthuan').window({
        width: 600,
        height: 300,
        modal: true,
        shadow: false,
        closed: true,
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: false
    });
    //单一商品替换，新替换
    $("#btnspthuan").click(function () {
        alert('已更改为直接可以修改商品明细\r\n请直接在商品明细修改');
        return;
        var rows = _$order.datagrid('getSelections');
        if (rows.length == 0) {
            alert('请选择一个订单');
            return;
        }
        if (rows.length != 1) {
            alert('只能选择一笔订单!');
            return;
        }
        var oStatusId = rows[0].OrderStatusId;
        if (oStatusId != 1) {
            alert("只有新导入的订单才可以进行商品替换");
            return;
        }
        var oids = rows[0].OrderId;
        var ebayuserid = rows[0].EbayUserId;
        $('#ddlOrdersLineitemId').combobox({
            url: "../../TableHanders.aspx?act=q&tid=1010&type=1&ebayUserId=" + ebayuserid + "&OrderId=" + oids,
            valueField: 'OrderLineItemId',
            textField: 'OrderLineItemId',
            onSelect: function (record) {
                var orderlineid = $('#ddlOrdersLineitemId').combobox('getValue');
                $("#ddlProduct").combobox({
                    url: "../../TableHanders.aspx?act=q&tid=1019&type=1&ebayUserId=" + ebayuserid + "&OrderId=" + oids + "&oitmeId=" + orderlineid,
                    valueField: 'ProductId',
                    textField: 'ProductId'
                });
            }
        });
        $("#txtebayuserid").val(ebayuserid);
        $('#pthuan').window('open');
    });

    $("#btnthclose").click(function () {
        $('#pthuan').window('close');
    });

    $("#btnthok").click(function () {
        var olineid = $('#ddlOrdersLineitemId').combobox('getValue');
        var ebayid = $("#txtebayuserid").val();
        var opid = $('#ddlProduct').combobox('getValue');
        var npid = $("#txtProductB").val();
        var oq = $("#txtOrginalQuantity").val();
        var nq = $("#txtNewQuantity").val();
        var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=xinspthuan&oq=" + oq + "&nq=" + nq + "&opid=" + opid + "&npid=" + npid + "&ebayid=" + ebayid + "&olineid=" + olineid + "&ts=" + new Date().getTime();
        $.getJSON(url, function (data) {
            var retData = EvalData(data);
            var code = retData.retCode;
            if (code == 0) {
                alert("替换成功!!");
                $("#ddlProduct").val("");
                $("#txtProductB").val("");
                $('#pthuan').window('close');
                _$order.datagrid("clearSelections");
            }
            else {
                alert(retData.retMsg);
            }
        });
    });

    $('#txtProductB').autocomplete('../../TableHanders.aspx?act=q&tid=1018&type=2', {
        minChars: 1, //minChars表示在自动完成激活之前填入的最小字符
        max: 10, //max表示列表里的条目数
        mustMatch: false, //mustMatch表示必须匹配条目，也就是在文本框里输入的内容，必须是data参数里的数据，如果不匹配，文本框就被清空
        matchContains: true, //表示包含匹配，也就是只要data数据里面有关键字就显示，不管它在什么位置，比如：google,omg;如果输入o,两个都显示
        scrollHeight: 100, //定高
        width: 500,
        matchCase: 1,
        matchSubset: 0,
        formatItem: function (data, i, total) {
            return data[0] + '  ,   ' + data[1] + '   ,   ' + data[2];
        },
        formatMatch: function (data, i, total) {
            return data[1];
        },
        formatResult: function (data) {
            return data[0];
        }

    });
    //替换结束

    //作废
    $("#btnInvalidOrder").click(function () {
        Order.InvalidOrder.Exec();
    });

    //替换查询开始
    $("#divthlog").window({
        width: 600,
        height: 220,
        modal: true,
        shadow: false,
        closed: true,
        collapsible: false,
        minimizable: false,
        maximizable: false
    });
    $("#btnthcxun").click(function () {
        var rows = _$order.datagrid('getSelections');
        if (rows.length == 0) {
            alert('请选择一个订单');
            return;
        }
        if (rows.length > 1) {
            alert('只能选择一个订单!');
            return;
        }
        var ebayUserId = rows[0].EbayUserId;
        var OrderId = rows[0].OrderId;
        $("#divthlog").window('open');
        LoadProductReplace(ebayUserId, OrderId);
    });
    //替换查询结束


    //订单合并
    $("#btnMergeOrders").click(function () {
        Order.MergeOrder.Exec();
    });
    //订单合并结束

    //显示关联
    $("#divddglian").window({
        width: 780,
        height: 220,
        modal: true,
        shadow: false,
        closed: true,
        collapsible: false,
        minimizable: false,
        maximizable: false
    });
    $("#btnxsglian").click(function () {
        var rows = _$order.datagrid('getSelections');
        if (rows.length == 0) {
            alert('请选择一个订单');
            return;
        }
        if (rows.length > 1) {
            alert('只能选择一个订单!');
            return;
        }
        var ebayUserId = rows[0].EbayUserId;
        var timeFrom = $("#beginDate").datebox('getValue');
        var timeTo = $("#endDate").datebox('getValue');
        var BuyerId = rows[0].UserId;
        var buyerFullName = rows[0].BuyerFullName;
        $("#divddglian").window('open');
        LoadGlProduct(ebayUserId, timeFrom, timeTo, BuyerId, buyerFullName);
    });
    //显示关联结束

    //订单导出
    //    $("#btnExpore").click(function () {
    //        if (!confirm('确认执行导出操作吗?'))
    //            return;
    //        var ebayUserId = $("#ddlebayUserId").combobox('getValue');
    //        var orderId = $("#txtOrderId").val();
    //        var BuyerId = $("#txtBuyerId").val();
    //        var BuyerName = $("#txtBuyerName").val();
    //        var NewOrderId = $("#txtNewOrderId").val();
    //        var OrderStatusId = $("#ddlOrderStatusId").combobox('getValue');
    //        var Standard = $("#ddlStandard").combobox('getValue');
    //        var ResendReason = $("#txtResendReason").val();
    //        var itemId = $("#txtItemId").val();
    //        var userCode = $("#txtUserCode").val();
    //        var reason = $("#txtRetentionReson").val();
    //        var FZR = $("#ddlFZR").combobox('getValue');
    //        var qtype = 0;
    //        var resend = "false";
    //        var memo = 0;
    //        var DE = 0;
    //        if ($("#chkquantity").attr("checked")) {
    //            qtype = "1";
    //        }
    //        else {
    //            qtype = "0";
    //        }

    //        if ($("#chkresend").attr("checked")) {
    //            resend = "true";
    //        }
    //        else {
    //            resend = "false";
    //        }

    //        if ($("#chkmemo").attr("checked")) {
    //            memo = "1";
    //        }
    //        else {
    //            memo = "0";
    //        }

    //        if ($("#chkDE").attr("checked")) {
    //            DE = "1";
    //        }
    //        else {
    //            DE = "0";
    //        }
    //        var s = $("#rppei").attr('checked');
    //        var s2 = $("#rxdan").attr('checked');
    //        var s3 = $("#rxgai").attr('checked');
    //        var rtype = 1;
    //        var timeFrom;
    //        var timeTo;
    //        if (s) {
    //            rtype = 1;
    //            timeFrom = $("#beginDate").datebox('getValue');
    //            timeTo = $("#endDate").datebox('getValue');
    //        }
    //        else if (s2) {
    //            rtype = 2;
    //            timeFrom = $("#xdbeginDate").datebox('getValue');
    //            timeTo = $("#xdendDate").datebox('getValue');
    //        }
    //        else if (s3) {
    //            rtype = 3;
    //            timeFrom = $("#xgbeginDate").datebox('getValue');
    //            timeTo = $("#xgendDate").datebox('getValue');
    //        }
    //        WaitBox.Show();
    //        var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=ordersExpore&ebayUserId=" + ebayUserId + "&timeFrom=" + timeFrom + "&timeTo=" + timeTo + "&orderId=" + orderId + "&BuyerId=" + BuyerId + "&BuyerName=" + BuyerName + "&NewOrderId=" + NewOrderId + "&OrderStatusId=" + OrderStatusId + "&Standard=" + Standard + "&rtype=" + rtype + "&itemId=" + itemId + "&userCode=" + userCode + "&reason=" + reason + "&qtype=" + qtype + "&resend=" + resend + "&memo=" + memo + "&ResendReason=" + ResendReason + "&FZR=" + FZR + "&DE=" + DE + "&ts=" + new Date().getTime();
    //        $.getJSON(url, function (data) {
    //            WaitBox.Close();
    //            var retData = EvalData(data);
    //            var code = retData.retCode;
    //            if (code == 0) {
    //                alert("导出完成");
    //            }
    //            else {
    //                alert(retData.retMsg);
    //            }
    //        });
    //    });

    //取消订单保留
    $("#btnCancelRetentionOrder").click(function () {
        Order.CancelRetentionOrder.Exec();
    });

    //取消匹配
    $("#btnCancelMatch").click(function () {
        Order.CancelMatch.Exec();
    });

    //反审核
    $("#btnCancelAudit").click(function () {
        Order.CancelAudit.Exec();
    });

    // 取消待审
    $("#btnCancelPreAudit").click(function () {
        Order.CancelPreAudit();
    });

    //拆分订单
    $("#btnSplitOrder").click(function () {
        Order.SplitOrder.Exec();
    });
    //拆分订单结束

    //客户退款
    //    $("#RefundMoneyWindow").window({
    //        width: 300,
    //        height: 245,
    //        modal: true,
    //        shadow: false,
    //        closed: true,
    //        collapsible: false,
    //        minimizable: false,
    //        maximizable: false
    //    });

    //退款按钮
    $("#btnRefundMoney").click(function () {
        Order.RefundMoney.Exec();
    });

    //    //退款取消弹窗
    //    $("#btnRefundMoneyCancel").click(function () {
    //        $("#RefundMoneyWindow").window('close');
    //    })

    //退款确认
    //    $("#btnRefundMoneyOK").click(function () {
    //        Order.data.ebayuserId = $("#txtRefundMoneyEbayUserId").val();
    //        Order.data.orderId = $("#txtRefundMoneyOrderId").val();
    //        Order.data.totalPrice = $("#txtRefundMoney").val();
    //        Order.data.did = $("#ddltkdisputeStatus").val();
    //        Order.data.rid = $("#ddltkrefType").val();
    //        Order.data.dpId = $("#ddltkdepartment").val();

    //        var rows = $("#tbOrderDetail").datagrid('getSelections');

    //        var data = [];
    //        var row = {};
    //        var pdata = {};
    //        for (var i = 0; i < rows.length; i++) {
    //            var quantity = rows[i].Qty;
    //            if (quantity <= 0) {
    //                alert('数量必须大于0');
    //                return;
    //            }
    //            if (parseInt(quantity, 0) > parseInt(rows[i].Quantity, 0)) {
    //                alert('发货数量不能大于原数量');
    //                return;
    //            }
    //            row = rows[i];
    //            row.Quantity = quantity;
    //            data[data.length] = row;
    //        }

    //        var confirmMsg = Order.confirmMsg ? Order.confirmMsg : '确认执行此操作吗?';
    //        if (!confirm(confirmMsg)) {
    //            return;
    //        }
    //        $("#RefundMoneyWindow").dialog('close');

    //        if ($("#rdcheckorder").attr('checked')) {
    //            if (!Order.CheckSelected())
    //                return;
    //        }
    //        Order.LoadQueryData();
    //        Order.Exec();
    //    });
    //客户退款结束

    //客户退货
    //    $("#btnReturnProduct").click(function () {
    //        // alert('此功能暂关闭!');修改时间：2012-10-08
    //        Order.RetrunProduct.Exec();
    //    });

    //生成订单明细
    $("#btnCOrderDetail").click(function () {
        Order.COrderDetail.Exec();
    });

    //订单过期作废
    $("#btnInvalidOrderOutDate").click(function () {
        Order.InvalidOrderOutDate();
    });

    //不完全代码处理
    $("#btnCustomLableCompleteHandle").click(function () {
        Order.customLableCompleteHandle.Exec();
    });

    //不完全代码批量处理

    $("#btnProcessMoreNoCompleteOrder").click(function () {
        Order.MoreNoCompleteProcess();
    })

    $("#divSelectDate").window({
        width: 400,
        height: 240,
        modal: true,
        shadow: false,
        closed: true,
        collapsible: false,
        minimizable: false,
        maximizable: false
    });

    $("#btnCheckOK").click(function () {
        var confirmMsg = Order.confirmMsg ? Order.confirmMsg : '确认执行不完全代码批量处理?';
        if (!confirm(confirmMsg)) {
            return;
        }
        Order.data.ProDate = $("#txtHandleDate").datebox('getValue');
        $("#divSelectDate").dialog('close');
        Order.Exec();
    });

    $("#btnCheckCancel").click(function () {

        $("#divSelectDate").window('close');
    });
    //批量操作开始
    $("#CheckQueryWindow").dialog({
        width: 220,
        height: 160,
        modal: true,
        shadow: false,
        closed: true,
        collapsible: false,
        minimizable: false,
        maximizable: false
    });

    //订单重发
    $("#btnReBuilderOrder").click(function () {
        Order.ReBuilderOrder();
    });
    //订单重发结束

    //批量审核
    //    $("#btnAudit").click(function () {
    //        Order.Audit();
    //    });

    //按帐号批量审核,一个帐号生成一张单据
    $("#btnAuditMore").click(function () {
        $('#dlgAuditMore').dialog('open');
        //Order.MoreAudit();
    });

    // 保留处理，对未审核的订单经行库存检查
    $("#btnblchul").click(function () {
        Order.BlChuL();
    });

    //发货取消
    $("#btnPayMent").click(function () {
        Order.CancelParcel.Exec();
    });

    //批量打印
    $("#btnOrderPrint").click(function () {
        Order.OrderPrint();
    });

    //批量预打印
    $("#OrderPrintExpect").click(function () {
        Order.OrderPrintExpect();
    });

    $("#btnCheckQueryCancel").click(function () {
        $("#CheckQueryWindow").dialog('close');
    });

    $("#btnCheckQueryOK").click(function () {
        var confirmMsg = Order.confirmMsg ? Order.confirmMsg : '确认执行此操作吗?';
        if (!confirm(confirmMsg)) {
            return;
        }

        $("#CheckQueryWindow").dialog('close');

        if ($("#rdcheckorder").attr('checked')) {
            if (!Order.CheckSelected())
                return;
        }
        Order.LoadQueryData();
        Order.Exec();
    });
    //批量操作结束

    //批量修改开始
    $("#UpdateOrdersWindow").window({
        width: 300,
        height: 140,
        modal: true,
        shadow: false,
        closed: true,
        collapsible: false,
        minimizable: false,
        maximizable: false
    });
    $("#btnUpdateOrders").click(function () {
        Order.UpdateOrders();
    });
    $("#btnUpdateOrdersCancel").click(function () {
        $("#UpdateOrdersWindow").window('close');
    });

    //保留重置
    $("#btnResetReserve").click(function () {
        if (!confirm('确认执行批量操作吗?'))
            return;
        Order.ResetReserve();
    });

    $("#btnUpdateOrdersOK").click(function () {
        alert('暂不支持');
        return;
        //        var statusId = $("#ddlStatusId").val();
        //        var deliveryId = $("#ddlDeliveryId").val();
        //        if (statusId == " " && deliveryId == " ") {
        //            alert("修改状态和发货方式不能为空!!");
        //            return;
        //        }

        //        if (!confirm('确认进行批量修改吗?'))
        //            return;

        //        $("#UpdateOrdersWindow").window('close');
        //        Order.data.data = Order.getSelectedDataToJson();
        //        Order.data.deliveryId = deliveryId;
        //        Order.data.statusId = statusId;
        //        Order.Exec();
    });
    //批量修改结束
    //手动保留开始
    $("#Divshdbliu").window({
        width: 300,
        height: 130,
        modal: true,
        shadow: false,
        closed: true,
        collapsible: false,
        minimizable: false,
        maximizable: false
    });
    $("#btnshdbliu").click(function () {
        var rows = Order.GetSelectedRows();
        if (rows.length == 0) {
            alert('请选择一个订单');
            return;
        }
        for (i = 0; i < rows.length; i++) {
            if (rows[i].OrderStatusId == 2) {
                alert("已审核的订单不能手动保留！..");
                return false;
            }
        }
        Order.ResetStatus();
        Order.data.cmd = 'shdbliu';
        $("#Divshdbliu").window('open');
    });
    $("#btnshdbliuCancel").click(function () {
        $("#Divshdbliu").window('close');
    });
    $("#btnshdbliuOK").click(function () {
        var reason = $("#txtReason").val();
        $("#Divshdbliu").window('close');
        Order.data.data = Order.getSelectedDataToJson();
        Order.data.reason = reason;
        Order.Exec();
    });
    //手动保留结束
});

var Order = {

    //订单datagrid
    _Order: null,

    //发送命令的集合
    data: {},

    //执行成功后显示的信息
    successMsg: null,

    //操作成功后打开的页面
    SuccessUrl: null,

    //操作成功后是否刷新
    SuccessRefresh: true,

    //执行前询问的讯息
    confirmMsg: null,

    //重置所有状态
    ResetStatus: function () {
        Order.data = {};
        Order.successMsg = null;
        Order.SuccessUrl = null;
        Order.SuccessRefresh = true;
        Order.confirmMsg = null;
    },

    parsJson: function (source) {
        var val = {};
        try {
            val = eval(source)[0];
        }
        catch (e) {
            val.retCode = 1;
            val.retMsg = '服务器内部错误';
        }
        return val;
    },
    CheckSelected: function () {
        var rows = this._Order.datagrid('getSelections');
        if (rows.length == 0) {
            alert('请至少选择一条订单');
            return false;
        }
        return true;
    },
    CheckSelectSingleRow: function () {
        var rows = this._Order.datagrid('getSelections');
        if (rows.length == 0) {
            alert('请至少选择一条订单');
            return false;
        }
        else if (rows.length > 1) {
            alert('此操作不支持多选操作,请去掉多余选项');
            return false;
        }
        return true;
    },
    GetSelectedRows: function () {
        var rows = this._Order.datagrid('getSelections');
        return rows;
    },
    ReLoadData: function () {
        this._Order.datagrid('reload');
    },
    getSelectedDataToJson: function () {
        var rows = Order.GetSelectedRows();
        var data = [];
        for (i = 0; i < rows.length; i++) {
            var row = {};
            row.EbayUserId = rows[i].EbayUserId;
            row.OrderId = rows[i].OrderId;
            row.OrderLineItemId = rows[i].OrderLineItemId;
            data[i] = row;
        }
        return $.toJSON(data);
    },
    LoadToday: function () {
        Order.data.etype = 1;
    },

    getParasData: function () {
        var data = {};
        data.EbayUserId = $("#ddlebayUserId").combobox('getValue');
        data.orderId = $("#txtOrderId").val();
        data.BuyerId = $("#txtBuyerId").val();
        data.BuyerName = $("#txtBuyerName").val();
        data.NewOrderId = $("#txtNewOrderId").val();
        data.OrderStatusId = $("#ddlOrderStatusId").combobox('getValue');
        data.Standard = $("#ddlStandard").combobox('getValue');
        data.ResendReason = $("#txtResendReason").val();
        data.ItemId = $("#txtItemId").val();
        data.userCode = $("#txtUserCode").val();
        data.Reason = $("#txtRetentionReson").val();
        data.FZR = $("#ddlFZR").combobox('getValue');
        if ($("#chkquantity").attr("checked")) {
            data.qtype = "1";
        }
        else {
            data.qtype = "0";
        }

        if ($("#chkresend").attr("checked")) {
            data.resend = "true";
        }
        else {
            data.resend = "false";
        }

        if ($("#chkmemo").attr("checked")) {
            data.memo = "1";
        }
        else {
            data.memo = "0";
        }

        if ($("#chkDE").attr("checked")) {
            data.DE = "1";
        }
        else {
            data.DE = "0";
        }
        var s = $("#rppei").attr('checked');
        var s2 = $("#rxdan").attr('checked');
        var s3 = $("#rxgai").attr('checked');
        var rtype = 1;
        if (s) {
            data.rtype = 1;
            data.timeFrom = $("#beginDate").datebox('getValue');
            data.timeTo = $("#endDate").datebox('getValue');
        }
        else if (s2) {
            data.rtype = 2;
            data.timeFrom = $("#xdbeginDate").datebox('getValue');
            data.timeTo = $("#xdendDate").datebox('getValue');
        }
        else if (s3) {
            data.rtype = 3;
            data.timeFrom = $("#xgbeginDate").datebox('getValue');
            data.timeTo = $("#xgendDate").datebox('getValue');
        }
        return data;
    },
    LoadQueryData: function () {
        if ($("#rdcheckorder").attr('checked')) {
            Order.data.etype = 3;
            Order.data.data = Order.getSelectedDataToJson();
        }
        else if ($("#rdcurrent").attr('checked')) {
            Order.data.etype = 2;
            var d = Order.getParasData();
            for (var k in d) {
                Order.data[k] = d[k];
            }
        }
        else {
            Order.LoadToday();
        }
    },

    Exec: function () {
        $.ajax({
            type: "post",
            url: "OrdersHandler.ashx?ts=" + new Date().getTime(),
            data: Order.data,
            beforeSend: function (XMLHttpRequest) {
                WaitBox.Show();
            },
            success: function (data, textStatus) {
                WaitBox.Close();

                var retData = Order.parsJson(data);
                var code = retData.retCode;
                var Msg = retData.retMsg;
                var fn = retData.fn;
                if (code == 0) {
                    if (fn) {
                        var durl = getRootPath() + "/Download.aspx?file=" + fn;
                        $("#diframe").attr('src', durl);
                        return;
                    }
                    if (Order.successMsg) {
                        alert(Order.successMsg);
                    }
                    else {
                        alert('操作成功');
                    }
                    if (Order.SuccessRefresh) {
                        Order.ReLoadData();
                    }
                    if (Order.SuccessUrl) {
                        window.open(Order.SuccessUrl);
                    }
                }
                else {
                    if (retData.retMsg) {
                        alert(retData.retMsg);
                    }
                    else {
                        alert('操作失败');
                    }
                }
            },
            error: function () {
                alert('服务器内部错误');
                WaitBox.Close();
            }
        });
    },
    //审核
    //    Audit: function () {
    //        $("#CheckQueryWindow").dialog('open');
    //        Order.ResetStatus();
    //        Order.SuccessUrl = 'Result.htm'
    //        Order.successMsg = '操作完成';
    //        Order.confirmMsg = '确认执行审核操作吗?';
    //        Order.data.cmd = 'Audit';
    //    },
    //打印
    OrderPrint: function () {
        $("#CheckQueryWindow").dialog('open');
        Order.ResetStatus();
        Order.confirmMsg = '确认执行打印操作吗?';
        Order.data.cmd = 'OrderPrint';
        Order.SuccessRefresh = false;
    },
    //预打印
    OrderPrintExpect: function () {
        $("#CheckQueryWindow").dialog('open');
        Order.ResetStatus();
        Order.confirmMsg = '确认执行预打印操作吗?';
        Order.data.cmd = 'OrderPrintExpect';
        Order.SuccessRefresh = false;
    },
    //确认付款(改为发货取消)
    PayMent: function () {
        $("#CheckQueryWindow").dialog('open');
        Order.ResetStatus();
        Order.successMsg = '操作完成';
        Order.confirmMsg = '确认订单已付款?';
        Order.data.cmd = 'PayMent';
    },
    //订单重发
    ReBuilderOrder: function () {
        if (!this.CheckSelectSingleRow())
            return;
        var rows = this.GetSelectedRows();

        //2012-7-27 修改“退款和退货”也可以重发
        var oStatusId = rows[0].OrderStatusId;
        var newID = rows[0].NewOrderId;
        if (newID != "") {
            alert('重发订单不能重发');
            return;
        }
        if (oStatusId != 1) {
            var ebayUserId = rows[0].EbayUserId;
            var orderId = rows[0].OrderId;
            var ret = window.showModalDialog("ReBuilderOrder.aspx?OrderId=" + orderId + "&EbayUserId=" + ebayUserId + "&ts=" + new Date().getTime(), "", "dialogHeight:400px;dialogWidth:875px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;"); //原来dialogHeight:400px;dialogWidth:610px;
            if (ret) {
                Order.ReLoadData();
            }
        }
        else {
            alert('未审核状态订单不能重发');
            return;
        }
    },
    //退款
    RefundMoney: {
        CheckStatus: function (rows) {
            if (rows.length == 0) {
                alert('请选择一个订单');
                return false;
            }
            if (rows.length > 1) {
                alert('只能选择一个订单!');
                return false;
            }
            var oStatusId = rows[0].OrderStatusId;
            var msId = rows[0].MatchStatusId;
            var isPay = rows[0].IsPay;
            if (isPay != "Y") {
                alert('已匹配并且已付款的订单才可以进行退款');
                return false;
            }
            if (msId != 2) {
                alert('已匹配并且已付款的订单才可以进行退款');
                return false;
            }
            //            if (oStatusId == 4) {
            //                alert('已作废的订单不能退款');
            //                return false;
            //            }
            //            if (oStatusId == 5) {
            //                alert("已退款的订单不能退款");
            //                return false;
            //            }
            //            if (oStatusId == 6) {
            //                alert("已退货的订单不能退款");
            //                return false;
            //            }
            //            else if (oStatusId == 8) {
            //                alert('已合并的订单不能在退款');
            //                return false;
            //            }
            //            else if (oStatusId == 9) {
            //                alert('已拆分的订单不能退款');
            //                return false;
            //            }
            return true;
        },
        //获得PPGross
        //        GetPPGross: function () {
        //            var rows = Order.GetSelectedRows();
        //            if (!Order.RefundMoney.CheckStatus(rows))
        //                return;
        //            var ebayUserId = rows[0].EbayUserId;
        //            var orderId = rows[0].OrderId;
        //            var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=getppgross&ebayid=" + ebayUserId + "&oid=" + orderId + "&ts=" + new Date().getTime();
        //            $.getJSON(url, function (data) {
        //                var retData = EvalData(data);
        //                var code = retData.retCode;
        //                var money = retData.retMsg;
        //                if (code == 0) {
        //                    $("#txtRefundMoney").val(money);
        //                    Order.RefundMoney.Exec();
        //                }
        //                else {
        //                    alert(retData.retMsg);
        //                }
        //            });
        //        },
        Exec: function () {
            var rows = Order.GetSelectedRows();
            if (!Order.RefundMoney.CheckStatus(rows))
                return;
            var eBayUserId = rows[0].EbayUserId;
            var orderId = rows[0].OrderId;
            var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=RefundAlready&EbayUserId=" + eBayUserId + "&OrderId=" + orderId + "&ts=" + new Date().getTime();
            $.getJSON(url, function (data) {
                var retData = EvalData(data);
                var code = retData.retCode;
                var Msg = retData.retMsg;
                if (code == 1) {
                    if (!confirm('此订单已有' + Msg + '张退款单!确认继续退款么?')) {
                        return;
                    }
                    else {
                        var ret = window.showModalDialog("CreateRefundOrder.aspx?OrderId=" + orderId + "&EbayUserId=" + eBayUserId + "&ts=" + new Date().getTime(), "", "dialogHeight:400px;dialogWidth:875px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;"); //原来dialogHeight:400px;dialogWidth:610px;
                    }
                }
                else {
                    var ret = window.showModalDialog("CreateRefundOrder.aspx?OrderId=" + orderId + "&EbayUserId=" + eBayUserId + "&ts=" + new Date().getTime(), "", "dialogHeight:400px;dialogWidth:875px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;"); //原来dialogHeight:400px;dialogWidth:610px;
                }
            });
            //            $("#txtRefundMoneyEbayUserId").val(ebayUserId);
            //            $("#txtRefundMoneyOrderId").val(orderId);

            //            $("#RefundMoneyWindow").window('open');


            //            Order.ResetStatus();
            //            Order.successMsg = '操作完成';
            //            Order.confirmMsg = '确认退款吗?';
            //            Order.data.cmd = 'RefundMoney';
        }
    },

    //作废
    InvalidOrder: {
        CheckStatus: function (rows) {
            for (i = 0; i < rows.length; i++) {
                var oStatusId = rows[i].OrderStatusId;
                if (oStatusId == 1 || oStatusId == 3 || oStatusId == 4) {
                }
                else {
                    alert("只有保留状态和新导入状态订单才可以作废");
                    return false;

                }
            }
            return true;
        },
        Exec: function () {
            if (!Order.CheckSelected())
                return;
            if (!confirm('确认要作废订单吗?'))
                return;
            var rows = Order.GetSelectedRows();
            if (!Order.InvalidOrder.CheckStatus(rows))
                return;
            Order.ResetStatus();
            Order.successMsg = '操作完成';
            Order.confirmMsg = '确认要作废选中的订单?';
            Order.data.cmd = 'InvalidOrder';
            Order.data.data = Order.getSelectedDataToJson();
            Order.Exec();
        }
    },
    //合并订单
    MergeOrder: {
        CheckStatus: function (rows) {
            if (rows.length < 2) {
                alert('合并订单至少需要选择两项');
                return false;
            }
            for (i = 0; i < rows.length; i++) {
                var oStatusId = rows[i].OrderStatusId;
                if (oStatusId != 1) {
                    alert('只有新导入状态的订单才可以合并');
                    return false;
                }
            }
            return true;
        },
        Exec: function () {
            var rows = Order.GetSelectedRows();
            if (!Order.MergeOrder.CheckStatus(rows))
                return;
            Order.ResetStatus();
            Order.successMsg = '操作完成';
            Order.confirmMsg = '确认合并选中的订单?';
            Order.data.cmd = 'MergeOrders';
            Order.data.data = Order.getSelectedDataToJson();
            Order.Exec();
        }
    },
    //负评新增
    NewNegative: {
        CheckStatus: function (rows) {
            if (rows.length > 1) {
                alert('订单负评新增只能选择一项');
                return false;
            }
            return true;
        },
        Exec: function () {
            var rows = Order.GetSelectedRows();
            if (!Order.MergeOrder.CheckStatus(rows))
                return;
            Order.ResetStatus();
            Order.successMsg = '操作完成';
            Order.confirmMsg = '确认合并选中的订单?';
            Order.data.cmd = 'NewNegative';
            Order.data.data = Order.getSelectedDataToJson();
            Order.Exec();
        }
    },
    //取消匹配
    CancelMatch: {
        CheckStatus: function (rows) {
            if (rows.length == 0) {
                alert('请选择一个订单');
                return false;
            }
            for (i = 0; i < rows.length; i++) {
                var oStatusId = rows[i].OrderStatusId;
                var msId = rows[i].MatchStatusId;
                if (msId != 2 || oStatusId != 1) {
                    alert('只有新导入并且已匹配的订单才可以取消匹配');
                    return false;
                }
            }
            return true;
        },
        Exec: function () {
            var rows = Order.GetSelectedRows();
            if (!Order.CancelMatch.CheckStatus(rows))
                return;
            if (!confirm('确认取消匹配的订单吗?'))
                return;

            Order.ResetStatus();
            Order.successMsg = '操作完成';
            Order.confirmMsg = '确认取消匹配的订单?';
            Order.data.cmd = 'CancelMatch';
            Order.data.data = Order.getSelectedDataToJson();
            Order.Exec();
        }
    },
    customLableCompleteHandle: {
        CheckStatus: function (rows) {
            if (rows.length == 0) {
                alert('请选择一个订单');
                return false;
            }

            if (rows.length > 1) {
                alert('只能选择一个订单!');
                return false;
            }

            var oStatusId = rows[0].OrderStatusId;
            if (oStatusId != 1) {
                alert('只有新导入状态的订单才可以进行不完全处理');
                return false;
            }
            return true;
        },
        Exec: function () {
            var rows = Order.GetSelectedRows();
            if (!Order.customLableCompleteHandle.CheckStatus(rows))
                return;

            Order.ResetStatus();
            var ebayUserId = rows[0].EbayUserId;
            var orderId = rows[0].OrderId;
            var url = getRootPath() + "/UI/Orders/NoCompleteCustomLableHander.aspx?orderId=" + orderId + "&ebayUserId=" + ebayUserId + "&ts=" + new Date().getTime();
            window.showModalDialog(url, "", "dialogHeight:410px;dialogWidth:770px;edge:Raised;center:Yes;help:No;resizable:no;status:no;location=no;");
        }
    },
    //发货取消
    CancelParcel: {
        CheckStatus: function (rows) {
            if (rows.length == 0) {
                alert('请选择一个订单');
                return false;
            }
            if (rows.length > 1) {
                alert('只能选择一个订单!');
                return false;
            }
            if (!(rows[0].OrderStatusId == 2 || rows[0].OrderStatusId == 10)) {
                alert('必须是审核过的单据才可以取消发货');
                return false;
            }
            return true;
        },
        Exec: function () {
            var rows = Order.GetSelectedRows();
            if (!Order.CancelParcel.CheckStatus(rows)) {
                return;
            }
            Order.ResetStatus();
            Order.successMsg = '操作完成';
            Order.data.ebayUserId = rows[0].EbayUserId;
            Order.data.orderId = rows[0].OrderId;
            if (rows[0].OrderStatusId == 2) {
                Order.data.cmd = 'CancelParcel2';
            }
            else if (rows[0].OrderStatusId == 10) {
                Order.data.cmd = 'CancelParcel10';
            }
            Order.Exec();
        }
    },
    //退货
    RetrunProduct: {
        CheckStatus: function (rows) {
            if (rows.length == 0) {
                alert('请选择一个订单');
                return false;
            }
            if (rows.length > 1) {
                alert('只能选择一个订单!');
                return false;
            }
            if (rows[0].OrderStatusId != 2) {
                alert('必须是审核过的单据才可以退货');
                return false;
            }
            return true;
        },
        Exec: function () {
            var rows = Order.GetSelectedRows();
            if (!Order.RetrunProduct.CheckStatus(rows)) {
                return;
            }

            if (!confirm('确认退货吗?'))
                return;

            Order.ResetStatus();
            Order.successMsg = '操作完成';
            Order.data.ebayUserId = rows[0].EbayUserId;
            Order.data.orderId = rows[0].OrderId;
            Order.data.cmd = 'RetrunProduct';
            Order.Exec();
        }
    },
    //生成订单明细
    COrderDetail: {
        CheckStatus: function (rows) {
            if (rows.length == 0) {
                alert('请选择一个订单');
                return false;
            }
            if (rows.length > 1) {
                alert('只能选择一个订单!');
                return false;
            }
            return true;
        },
        Exec: function () {
            var rows = Order.GetSelectedRows();
            if (!Order.COrderDetail.CheckStatus(rows)) {
                return;
            }

            if (!confirm('确认生成订单明细么?'))
                return;

            Order.ResetStatus();
            Order.successMsg = '操作完成';
            Order.data.ebayUserId = rows[0].EbayUserId;
            Order.data.orderId = rows[0].OrderId;
            Order.data.cmd = 'COrderDetail';
            Order.Exec();
        }
    },
    //订单过期作废
    InvalidOrderOutDate: function () {

        if (!confirm('确认作废已过期的订单吗?'))
            return;
        Order.ResetStatus();
        Order.successMsg = '操作完成';
        Order.data.cmd = 'InvalidOrderOutDate';
        Order.Exec();
    },
    //取消保留
    CancelRetentionOrder: {
        CheckStatus: function (rows) {
            if (rows.length == 0) {
                alert('请选择一个订单');
                return false;
            }
            for (i = 0; i < rows.length; i++) {
                if (rows[i].OrderStatusId != 3 && 11 != rows[i].OrderStatusId) {
                    alert("只有保留状态的订单才可以取消保留");
                    return false;
                }
            }

            return true;
        },
        Exec: function () {
            var rows = Order.GetSelectedRows();

            if (!Order.CancelRetentionOrder.CheckStatus(rows)) {
                return;
            }
            if (!confirm('确认取消保留的订单吗?'))
                return;

            Order.ResetStatus();
            Order.successMsg = '操作完成';
            Order.data.cmd = 'CancelRetentionOrder';
            Order.data.data = Order.getSelectedDataToJson();
            Order.Exec();
        }
    },
    //反审核
    CancelAudit: {
        //新反审核
        CheckStatus: function (rows) {
            if (rows.length == 0) {
                alert('请选择一个订单');
                return false;
            }
            if (rows.length > 1) {
                alert('只能选择一个订单!');
                return false;
            }
            if (rows[0].OrderStatusId != 2) {
                alert('必须是审核过的单据才可以反审核');
                return false;
            }
            if (Date.parse(rows[0].Atime.replace("-", "/")) < Date.parse(new Date().getFullYear() + "/" + (parseInt(new Date().getMonth()) + 1).toString() + "/" + new Date().getDate())) {
                alert('只能反审核当天审核的订单');
                return false;
            }
            return true;
        },
        Exec: function () {
            var rows = Order.GetSelectedRows();
            if (!Order.CancelAudit.CheckStatus(rows)) {
                return;
            }

            if (!confirm('确认反审核吗?'))
                return;

            Order.ResetStatus();
            Order.successMsg = '操作完成';
            Order.data.ebayUserId = rows[0].EbayUserId;
            Order.data.orderId = rows[0].OrderId;
            Order.data.cmd = 'CancelAudit';
            Order.Exec();
        }
        //        CheckStatus: function (rows) {
        //            if (rows.length == 0) {
        //                alert('请选择一个订单');
        //                return false;
        //            }
        //            for (i = 0; i < rows.length; i++) {
        //                if (rows[i].OrderStatusId != 2) {
        //                    alert("审核状态的订单才可以反审核");
        //                    return false;
        //                }
        //            }
        //            return true;
        //        },
        //        Exec: function () {
        //            var rows = Order.GetSelectedRows();

        //            if (!Order.CancelAudit.CheckStatus(rows)) {
        //                return;
        //            }

        //            if (!confirm('确认是反审核操作?')) {
        //                return;
        //            }

        //            Order.ResetStatus();
        //            Order.successMsg = '操作完成';
        //            Order.data.cmd = 'CancelAudit';
        //            Order.data.data = Order.getSelectedDataToJson();
        //            Order.Exec();
        //        }
    },
    //订单拆分
    SplitOrder: {
        CheckStatus: function (rows) {
            if (rows.length == 0) {
                alert('请选择一个订单');
                return false;
            }
            if (rows.length > 1) {
                alert('只能选择一个订单!');
                return false;
            }
            var oStatusId = rows[0].OrderStatusId;
            if (oStatusId != 1) {
                alert('只有新导入状态的订单才可以进行拆分');
                return false;
            }
            return true;
        },
        Exec: function () {
            var rows = Order.GetSelectedRows();
            if (!Order.SplitOrder.CheckStatus(rows)) {
                return;
            }
            if (!confirm('确认拆分订单吗?'))
                return;

            Order.ResetStatus();
            Order.SuccessRefresh = true;
            var url = getRootPath() + "/UI/Orders/OrderSplit.aspx?orderId=" + rows[0].OrderId + "&ebayUserId=" + rows[0].EbayUserId + "&ts=" + new Date().getTime();
            var retValue = window.showModalDialog(url, "", "dialogHeight:250px;dialogWidth:820px;edge:Raised;center:Yes;help:No;resizable:no;status:no; scroll:no;location=no;");
            if (retValue) {
                Order.ReLoadData();
            }
        }
    },
    //批量修改
    UpdateOrders: function () {

        var rows = Order.GetSelectedRows();
        if (rows.length == 0) {
            alert('请选择一个订单');
            return;
        }
        var oStatusId = rows[0].OrderStatusId;
        if (oStatusId == 2) {
            alert('已审核的订单不能修改');
            return;
        }
        if (oStatusId == 4) {
            alert('已作废的订单不能修改');
            return;
        }
        if (oStatusId == 5) {
            alert("已退款的订单不能修改");
            return;
        }
        if (oStatusId == 6) {
            alert("已退货的订单不能修改");
            return;
        }
        Order.ResetStatus();
        Order.data.cmd = 'UpdateOrders';
        $("#UpdateOrdersWindow").window('open');
    },
    MoreNoCompleteProcess: function () {
        Order.ResetStatus();
        Order.SuccessUrl = 'bwqResult.htm'
        Order.successMsg = '操作完成';
        Order.confirmMsg = '是否确认已匹配检查，执行批量操作吗?';
        Order.data.cmd = 'MoreNoCompleteProcess';
        $("#divSelectDate").window('open');
    },
    ResetReserve: function () {
        Order.ResetStatus();
        Order.data.cmd = 'ResetReserve';
        Order.Exec();
    },
    //    MoreAudit: function (auditType, count) {
    //        if (!confirm('确认进行批量审核操作吗')) {
    //            return;
    //        }
    //        Order.ResetStatus();
    //        Order.data.cmd = 'AuditMore';
    //        var s = $("#rppei").attr('checked');
    //        var s2 = $("#rxdan").attr('checked');
    //        var s3 = $("#rxgai").attr('checked');
    //        var rtype = 1;
    //        if (s) {
    //            Order.data.itype = 0;
    //            Order.data.timeFrom = $("#beginDate").datebox('getValue');
    //            Order.data.timeTo = $("#endDate").datebox('getValue');
    //        }
    //        else if (s2) {
    //            Order.data.itype = 1;
    //            Order.data.timeFrom = $("#xdbeginDate").datebox('getValue');
    //            Order.data.timeTo = $("#xdendDate").datebox('getValue');
    //        }
    //        else if (s3) {
    //            data.itype = 2;
    //            data.timeFrom = $("#xgbeginDate").datebox('getValue');
    //            data.timeTo = $("#xgendDate").datebox('getValue');
    //        }
    //        Order.data.auditType = auditType;
    //        Order.data.count = count;
    //        Order.Exec();
    //    },
    AllPreAudit: function () {
        if (!confirm('确认进行全部待审操作吗?')) {
            return;
        }
        Order.ResetStatus();
        Order.data.cmd = 'AllPreAudit';
        Order.Exec();
    },
    PreAudit: function () {
        var rows = $("#orders").datagrid('getSelections');

        if (rows.length == 0) {
            alert('请选择一个订单');
            return;
        }

        if (!confirm('确认进行选中待审操作吗?')) {
            return;
        }
        Order.ResetStatus();
        Order.data.cmd = 'PreAudit';

        var orders = [];
        for (var i = 0; i < rows.length; i++) {
            orders[i] = { eBayUserId: rows[i].EbayUserId, OrderId: rows[i].OrderId, OrderLineItemId: rows[i].OrderLineItemId };
        }
        Order.data.orders = $.toJSON(orders);
        Order.Exec();
    },
    CancelPreAudit: function () {
        var rows = $("#orders").datagrid('getSelections');

        if (rows.length == 0) {
            alert('请选择一个订单');
            return;
        }

        if (!confirm('确认进行取消选中待审操作吗?')) {
            return;
        }
        Order.ResetStatus();
        Order.data.cmd = 'CancelPreAudit';

        var orders = [];
        for (var i = 0; i < rows.length; i++) {
            orders[i] = { eBayUserId: rows[i].EbayUserId, OrderId: rows[i].OrderId, OrderLineItemId: rows[i].OrderLineItemId };
        }
        Order.data.orders = $.toJSON(orders);
        Order.Exec();
    },
    Audit: function () {
        if (!confirm('确认进行审核操作吗')) {
            return;
        }
        Order.ResetStatus();
        Order.data.cmd = 'Audit';
        Order.Exec();
    },

    BlChuL: function () {
        //        if (!confirm('确认进行订单库存保留检查吗')) {
        //            return;
        //        }
        Order.ResetStatus();
        Order.data.cmd = 'blchul';
        Order.successMsg = '操作完成';
        Order.confirmMsg = '确认进行订单库存保留检查吗?';
        Order.Exec();
    }
};

